﻿#pragma once

#ifndef QCEFDEBUG_H
#define QCEFDEBUG_H

#include <time.h>
#include <vector>
#include <cstdarg>
#include <Windows.h>


void qcef_debug(const char* fmt, ...);
void qcef_warn(const char* fmt, ...);
void qcef_error(const char* fmt, ...);
void qcef_fatal(const char* fmt, ...);
void qcef_info(const char* fmt, ...);


#if (defined(QT_CEF_DEBUG))

    // DEBUG BUILD
    #define QCEF_DEBUG(format, ...)     qcef_debug(("[%s] [%d] [%s] tid=%d this=%I64d " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)
    #define QCEF_WARN(format, ...)      qcef_warn(("[%s] [%d] [%s] tid=%d this=%I64d " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)
    #define QCEF_ERROR(format, ...)     qcef_error(("[%s] [%d] [%s] tid=%d this=%I64d " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)
    #define QCEF_FATAL(format, ...)     qcef_fatal(("[%s] [%d] [%s] tid=%d this=%I64d " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)
    #define QCEF_INFO(format, ...)      qcef_info(("[%s] [%d] [%s] tid=%d this=%I64d " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)

    #define QCEF_DEBUG_F(format, ...)   qcef_debug(("[%s] [%d] [%s] tid=%d this=0 " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), ##__VA_ARGS__)
    #define QCEF_WARN_F(format, ...)    qcef_warn(("[%s] [%d] [%s] tid=%d this=0 " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), ##__VA_ARGS__)
    #define QCEF_ERROR_F(format, ...)   qcef_error(("[%s] [%d] [%s] tid=%d this=0 " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), ##__VA_ARGS__)
    #define QCEF_FATAL_F(format, ...)   qcef_fatal(("[%s] [%d] [%s] tid=%d this=0 " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), ##__VA_ARGS__)
    #define QCEF_INFO_F(format, ...)    qcef_info(("[%s] [%d] [%s] tid=%d this=0 " format "\r\n"), __FILE__, __LINE__, __FUNCTION__, ::GetCurrentThreadId(), ##__VA_ARGS__)

#else

    // RELEASE BUILD
    #define QCEF_DEBUG(format, ...)
    #define QCEF_WARN(format, ...)      qcef_warn(("tid=%d this=%I64d " format "\r\n"), ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)
    #define QCEF_ERROR(format, ...)     qcef_error(("tid=%d this=%I64d " format "\r\n"), ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)
    #define QCEF_FATAL(format, ...)     qcef_fatal(("tid=%d this=%I64d " format "\r\n"), ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)
    #define QCEF_INFO(format, ...)      qcef_info(("tid=%d this=%I64d " format "\r\n"), ::GetCurrentThreadId(), (int64_t)this, ##__VA_ARGS__)

    #define QCEF_DEBUG_F(format, ...)
    #define QCEF_WARN_F(format, ...)    qcef_warn(("tid=%d this=0 " format "\r\n"), ::GetCurrentThreadId(), ##__VA_ARGS__)
    #define QCEF_ERROR_F(format, ...)   qcef_error(("tid=%d this=0 " format "\r\n"), ::GetCurrentThreadId(), ##__VA_ARGS__)
    #define QCEF_FATAL_F(format, ...)   qcef_fatal(("tid=%d this=0 " format "\r\n"), ::GetCurrentThreadId(), ##__VA_ARGS__)
    #define QCEF_INFO_F(format, ...)    qcef_info(("tid=%d this=0 " format "\r\n"), ::GetCurrentThreadId(), ##__VA_ARGS__)

#endif


#endif // QCEFDEBUG_H

